home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / Abacus diskdrives IO.adf / CH6 / bitmap_analyser.c < prev    next >
C/C++ Source or Header  |  1978-06-28  |  8KB  |  284 lines

  1. /*-----------------------------------------------------*/
  2. /*                 Bitmap - Analyzer                   */
  3. /*                                                     */
  4. /*                   JEA, 08-15-87                     */
  5. /*-----------------------------------------------------*/
  6. #include <exec/exec.h>
  7. #include <devices/trackdisk.h>
  8. #include <intuition/intuition.h>
  9. #define ON 1L
  10. #define OFF 0L
  11. #define BLOCK_SIZE 128L
  12. #define BM_FLAG BLOCK_SIZE-50L
  13. #define BM_BLOCKS BLOCK_SIZE-49L
  14. extern struct MsgPort *CreatePort();
  15. extern struct IORequest *CreateExtIO();
  16. struct IntuitionBase *IntuitionBase;
  17. struct GfxBase *GfxBase;
  18. struct TextAttr MyFont =
  19. {
  20.    "topaz.font",
  21.    TOPAZ_EIGHTY,
  22.    FS_NORMAL,
  23.    FPF_ROMFONT,
  24. };
  25. struct NewScreen NewScreen =
  26. {
  27.    0,
  28.    0,
  29.    640,
  30.    200,
  31.    2,
  32.    0, 1,
  33.    HIRES|SPRITES,
  34.    CUSTOMSCREEN,
  35.    &MyFont,
  36.    "- BitMap -",
  37.    NULL,
  38.    NULL,
  39. };
  40. /*-----------------------------------------------------*/
  41. /*                Switch Motor on and off              */
  42. /*                                                     */
  43. /*                                                     */
  44. /*-----------------------------------------------------*/
  45. Motor( diskreq, on )
  46. struct IOExtTD *diskreq;
  47. LONG on;
  48. {
  49.    diskreq->iotd_Req.io_Length = on;
  50.    diskreq->iotd_Req.io_Command = TD_MOTOR;
  51.    DoIO(diskreq);
  52.    return(0);
  53. }
  54. /*-----------------------------------------------------*/
  55. /*             Read Block from Device indicated        */
  56. /*                                                     */
  57. /*                                                     */
  58. /*-----------------------------------------------------*/
  59. ReadBlock( diskreq, block, puffer, diskChangeCount )
  60. struct IOExtTD *diskreq;
  61. LONG block;
  62. APTR puffer;
  63. ULONG diskChangeCount;
  64. {
  65.    diskreq->iotd_Req.io_Length  = TD_SECTOR;
  66.    diskreq->iotd_Req.io_Data    = puffer;
  67.    diskreq->iotd_Req.io_Command = ETD_READ;
  68.    diskreq->iotd_Count          = diskChangeCount;
  69.    diskreq->iotd_Req.io_Offset  = block * TD_SECTOR;
  70.    if(DoIO(diskreq))
  71.       return(1);
  72.    return(0);
  73. }
  74. /*-----------------------------------------------------*/
  75. /*              Search for Bitmap-Block and read       */
  76. /*                                                     */
  77. /*                                                     */
  78. /*-----------------------------------------------------*/
  79. LONG
  80. ReadBitmap( diskreq, buf )
  81. struct IOExtTD *diskreq;
  82. LONG *buf;
  83. {
  84. ULONG diskChangeCount;
  85.    diskreq->iotd_Req.io_Command = TD_CHANGENUM;
  86.    DoIO(diskreq);
  87.    diskChangeCount = diskreq->iotd_Req.io_Actual;
  88.    Motor( diskreq, ON );
  89.    ReadBlock( diskreq, 880L, buf, diskChangeCount );
  90.    printf
  91.      ("Flag: %ld ,  Block#%ld \n", buf[BM_FLAG], buf[BM_BLOCKS] );
  92.    if( buf[BM_FLAG] )
  93.       ReadBlock( diskreq, buf[BM_BLOCKS], buf );
  94.    Motor( diskreq, OFF );
  95.    return( buf[BM_FLAG] );
  96. }
  97. /*-----------------------------------------------------*/
  98. /*         Display Bitmap of the Device indicated      */
  99. /*                                                     */
  100. /*                                                     */
  101. /*-----------------------------------------------------*/
  102. DisplayBitmap( diskreq, Screen )
  103. struct IOExtTD *diskreq;
  104. struct Screen *Screen;
  105. {
  106. LONG *buf;
  107. LONG x, y;
  108. ULONG loop;
  109. struct Window *Window;
  110. struct NewWindow NewWindow;
  111. ULONG MessageClass;
  112. USHORT code;
  113. LONG flag;
  114. struct Message *GetMsg();
  115. struct IntuiMessage *message;
  116.    NewWindow.LeftEdge = 0;
  117.    NewWindow.TopEdge = 0;
  118.    NewWindow.Width = 640;
  119.    NewWindow.Height = 160;
  120.    NewWindow.DetailPen = 0;
  121.    NewWindow.BlockPen = 1;
  122.    NewWindow.Title = " Bitmap ";
  123.    NewWindow.Flags = WINDOWCLOSE|SMART_REFRESH|ACTIVATE|
  124.                      WINDOWDRAG|WINDOWDEPTH|
  125.                      NOCAREREFRESH | GIMMEZEROZERO;
  126.    NewWindow.IDCMPFlags = CLOSEWINDOW|DISKINSERTED|DISKREMOVED;
  127.    NewWindow.Type = CUSTOMSCREEN;
  128.    NewWindow.FirstGadget = NULL;
  129.    NewWindow.CheckMark = NULL;
  130.    NewWindow.Screen = Screen;
  131.    NewWindow.BitMap = NULL;
  132.    NewWindow.MinWidth = 640;
  133.    NewWindow.MinHeight = 148;
  134.    NewWindow.MaxWidth = 640;
  135.    NewWindow.MaxHeight = 200;
  136.    if(( Window = (struct Window*) 
  137.                        OpenWindow( &NewWindow )) == NULL)
  138.      exit( FALSE );
  139.    SetAPen (Window->RPort, 1 );
  140.    Move( Window->RPort, 500, 33 );
  141.    Text( Window->RPort, "Side   0", 7 );
  142.    Move( Window->RPort, 500, 105 );
  143.    Text( Window->RPort, "Side   1", 7 );
  144.    Move( Window->RPort, 0, 146 );
  145.    Text( Window->RPort, "1", 1 );
  146.    Move( Window->RPort, 466, 146 );
  147.    Text( Window->RPort, "80", 2 );
  148.    Move( Window->RPort, 480, 8 );
  149.    Text( Window->RPort, "Sector 1.", 9 );
  150.    Move( Window->RPort, 480, 64 );
  151.    Text( Window->RPort, "Sector 11.", 10 );
  152.    Move( Window->RPort, 480, 80 );
  153.    Text( Window->RPort, "Sector 1.", 9 );
  154.    Move( Window->RPort, 480, 136 );
  155.    Text( Window->RPort, "Sector 11.", 10 );
  156.    buf = (LONG*) AllocMem( 512L, MEMF_CHIP );
  157.    ReadBitmap( diskreq, buf );
  158.    buf[0] &= 0x3fffffffL;
  159.    loop=30L;
  160.    for( x=0; x<80; ++x ){
  161.       for( y=0; y<22; ++y ){
  162.          if( buf[loop/32] & (1L << (loop % 32)) )
  163.             SetAPen (Window->RPort, 2 );
  164.          else
  165.             SetAPen (Window->RPort, 3 );
  166.          if (y > 10)
  167.             RectFill( Window->RPort, x*6, 
  168.                              (y+1)*6, x*6+4, (y+1)*6+4 );
  169.          else
  170.             RectFill( Window->RPort, x*6, y*6, x*6+4, y*6+4 );         ++loop;
  171.       }
  172.    }
  173.    FreeMem( buf, 512L );
  174.    Wait( 1<<Window->UserPort->mp_SigBit);
  175.     flag = TRUE;
  176.     do
  177.     {
  178.        if (message = (struct 
  179.               IntuiMessage *)GetMsg(Window->UserPort))  {
  180.          MessageClass = message->Class;
  181.          code = message->Code;
  182.          ReplyMsg(message);
  183.          switch (MessageClass) {
  184.   
  185.             case CLOSEWINDOW : flag = FALSE;
  186.                                break;
  187.             case DISKREMOVED :
  188.                                Text( Window->RPort, 
  189.                                      "Disk Removed", 11);
  190.                                break;
  191.          }   /* Case */
  192.        }  /* if */
  193.     }
  194.    while( flag );
  195.    CloseWindow( Window );
  196. }
  197. /*-----------------------------------------------------*/
  198. /*                 Close Libraries                     */
  199. /*                                                     */
  200. /*                                                     */
  201. /*-----------------------------------------------------*/
  202. CloseLibs()
  203. {
  204.    CloseLibrary( IntuitionBase );
  205.    CloseLibrary( GfxBase );
  206. }
  207. /*-----------------------------------------------------*/
  208. /*                    Open Libraries                   */
  209. /*                                                     */
  210. /*                                                     */
  211. /*-----------------------------------------------------*/
  212. LONG
  213. OpenLibs()
  214.  
  215. {
  216.    IntuitionBase = (struct IntuitionBase*)
  217.                    OpenLibrary("intuition.library", 0);
  218.    if ( IntuitionBase == NULL ) exit( FALSE );
  219.    GfxBase       = (struct GfxBase*)
  220.                    OpenLibrary("graphics.library", 0);
  221.    if (GfxBase == NULL) exit ( FALSE );
  222.    return( TRUE );
  223. }
  224. /*-----------------------------------------------------*/
  225. /*              Main-Program BITMAP-Analyzer           */
  226. /*                                                     */
  227. /*                (open Device and Screen)             */
  228. /*-----------------------------------------------------*/
  229. main()
  230. {
  231. struct MsgPort *diskport;
  232. struct IOExtTD *diskreq;
  233. struct Screen *Screen;
  234.    if (!OpenLibs()) exit(FALSE);
  235.    if ((diskport = CreatePort(0L,0)) == NULL)
  236.    {
  237.       printf("Port can't be opened\n");
  238.       exit(FALSE);
  239.    }
  240.    diskreq = (struct IOExtTD *)CreateExtIO(diskport,
  241.                       (long)sizeof(struct IOExtTD));
  242.    if (diskreq == 0)
  243.    {
  244.       printf("DiskRequest can't be created !, Error %ld\n",diskreq);
  245.  
  246.       DeletePort(diskport);
  247.       exit(FALSE);
  248.    }
  249.    if ( OpenDevice(TD_NAME, 0L, diskreq, 0L) )
  250.    {
  251.       printf("Device reports error!\n");
  252.       DeletePort(diskport);
  253.       DeleteExtIO(diskreq,(long)sizeof(struct IOExtTD));
  254.       exit(FALSE);
  255.    }
  256.  
  257.    if( (Screen = (struct Screen*)OpenScreen(&NewScreen)) == NULL )
  258.      exit( FALSE );
  259.    DisplayBitmap( diskreq, Screen );
  260.    DeleteExtIO(diskreq,(long)sizeof(struct IOExtTD));
  261.    DeletePort(diskport);
  262.    CloseScreen( Screen );
  263.    CloseLibs();
  264.    exit( TRUE );
  265. }
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.